#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<unordered_map>
using namespace std;

void solve()
{
    int n, q; cin >> n >> q;
    vector<vector<int>> arr1(n + 1, vector<int>(26, 0)), arr2(n + 1, vector<int>(26, 0));
    string s1, s2;
    cin >> s1 >> s2;
    s1.insert(0, " ");
    s2.insert(0, " ");
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            arr1[i][j] = arr1[i - 1][j];
            arr2[i][j] = arr2[i - 1][j];
        }
        arr1[i][s1[i] - 'a'] += 1;
        arr2[i][s2[i] - 'a'] += 1;
    }
    for (int i = 0; i < q; i++)
    {
        int ans = 0;
        int l, r; cin >> l >> r;
        for (int j = 0; j < 26; j++)
        {
            int a = arr1[r][j] - arr1[l - 1][j];
            int b = arr2[r][j] - arr2[l - 1][j];
            ans += max(0, b - a);
        }
        cout << ans << endl;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}